<template>
  <div class="breadcrumb-box">
    <ul class="XBreadcrumb">
      <li v-for="(el, i) in titleList" :key="i" @click="breadcrumbTurn(el, i)" :class="{
          notAllowed: i <= startIndex
        }">
        <span> {{ el }}</span>
        <i class="el-icon-arrow-right"></i>
      </li>
    </ul>
    <div v-show="is_show">
      <el-button @click="$router.back()" type="primary"> 返回</el-button>
    </div>
  </div>
</template>

<script>
let detailChilder = [
  'applicationList',
  'personnelCheckIn',
  'eventPersonnel',
  'UnitReaderRanking',
  'QuestionList',
  'answerdataStatistics',
  'resrictionsList',
  'DoubleawardList',
  'DoubleGiftList',
  'DoubleGiftSet',
  'dataStatistics',
  'entry',
  'typeWorks',
  'QuestionnaireInfo',
  'entryPicture',
  'pavilionSpecialview',
  'pavilionpersonnel',
  'seatListSpecialview',
  'seatListpersonnel',
  'seatListseat',
  'libraryDetails',
  'onlineDetails',
  'Punchworks',
  'entryInfo',
  'areaList',
  'Copywriting',
  'doubleResrictionsList',
  'scenicWorksType',
  'scenicEntry',
  'selfstudypersonnel',
  'Buildingentry',
  'teacherspersonnel',
  'articlePersonnel',
  'classroomPersonnel',
  'exhibitPersonnel',
  'teachersSpecialview',
  'specifyUser',
  'entryVideo',
  'inviteCodeEchart'
]
export default {
  name: 'XBreadcrumb',
  props: {
    title: {
      type: String,
      default: '',
      required: true
    },
    path: {
      type: String,
      default: '',
      required: true
    },
    startIndex: {
      type: String,
      default: '0'
    }
  },
  data() {
    return { is_show: false }
  },
  created() { },
  activated() { },
  computed: {
    titleList() {
      return this.title.split('/')
    }
  },
  methods: {
    //面包屑跳转
    breadcrumbTurn(el, i) {
      if (i > this.startIndex - 0) {
        let pathList = this.path.split('/')
        let path
        
        if (pathList.length == 3) {
          path = pathList.slice(0, i + 1).join('/')
        } else path = pathList.slice(0, i + 2).join('/')
        if (this.$route.query.action) {
          this.$delete(this.$route.query, 'action')
        }
        return
        // 部分可用部分不可用，暂时关闭，路由造成的问题，暂时不用，部分带参数的已凉，需要重置所有跳转逻辑和路由
        this.$router.push({
          path,
          query: this.$route.query
        })
      }
    }
  },
  watch: {
    $route: {
      handler(newRouter) {
        // console.log(newRouter.name)
        this.is_show = false
        detailChilder.filter(item => {
          if (newRouter.name == item) {
            return (this.is_show = true)
          }
        })
      },
      immediate: true
    }
  }
}
</script>

<style lang="scss" scoped>
.breadcrumb-box {
  display: flex;
  justify-content: space-between;
  width: 100%;
}
.XBreadcrumb {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  > li {
    display: flex;
    align-items: center;
    cursor: pointer;
    > span {
      font-size: 14px;
      font-family: MicrosoftYaHei;
      text-align: left;
      color: $textColorD;
    }
    > i {
      font-size: 12px;
      color: $textColorD;
    }
    &:last-child {
      > span {
        font-size: 14px;
        color: $textColorF;
        font-weight: bold;
      }
      > i {
        display: none;
      }
    }
  }
  > .notAllowed {
    cursor: not-allowed;
  }
}
</style>
